<?php
declare (strict_types = 1);

namespace app\admin\controller\wx;
class AutoReply extends WxBase
{
    protected $configModel;
    protected $configValidate;
    protected function initialize()
    {
        parent::initialize();
        $this->configModel = new \app\common\model\Config;
        $this->configValidate = new \app\common\validate\Config;
    }
    // 本接口仅能获取公众号在公众平台官网的自动回复功能中设置的自动回复规则，
    // 若公众号自行开发实现自动回复，或通过第三方平台开发者来实现，则无法获取
    public function current() {
        $res = $this->app->auto_reply->current();
        return json($res);
    }
    public function index() {
        $res = $this->configModel->where('name','in',['wx_reply_sub','wx_reply_auto'])->column('id,value,remark','name');
        return json($res);
    }
    public function setting() {
        $data = $this->request->post();
        if(array_key_exists('id', $data)){
            $this->configModel->where(['id'=>$data['id']])->save($data);
        } else {
            $data['scope'] = 'wx';
            $this->configModel->save($data);
        }
        return json('设置成功！');
    }
}
